<?php


namespace app\admin\service\setting;


use app\common\model\log\OperationLog;
use app\common\model\notice\UserNoticeLog;
use tmcore\base\BaseService;
use tmcore\exceptions\ValidateException;

class NoticeLogService extends BaseService
{
    /**
     * 获取消息日志列表
     * @return array
     */
    public static function getList(): array
    {
        // 搜索条件
        $searchParam = [
            '%like%' => ['account','title'],
            '=' => ['notice_type','send_type','scene','status'],
            'between_time' => 'create_time',
        ];
        $where = self::getSearchData($searchParam);

        // 返回分页数据
        return UserNoticeLog::page($where, self::getPageData(),'id,scene,account,title,content,notice_type,send_type,is_captcha,status,send_time,create_time', ['id' => 'desc'],['status_desc','notice_type_desc','send_type_desc']);
    }

    /**
     * 查看消息日志详情
     * @param $params
     * @return array
     */
    public static function detail($params) : array
    {
        if(empty($params['id'])) throw new ValidateException('参数异常');
        $row = UserNoticeLog::where(['id' => $params['id']])->append(['status_desc','notice_type_desc','send_type_desc','read_desc','read_time_desc','send_time_desc'])->hidden(['delete_time'])
            ->findOrEmpty();
        if ($row->isEmpty()) return [];
        return $row->toArray();
    }
}